//
//  XMLAnalysisVC.m
//  first
//
//  Created by 毕小强 on 16/11/14.
//  Copyright © 2016年 毕小强. All rights reserved.
//

#import "XMLAnalysisVC.h"
#import <GDataXMLNode.h>
@interface XMLAnalysisVC ()

@end

@implementation XMLAnalysisVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSMutableArray *arr = [NSMutableArray array];
    NSString *path = [[NSBundle mainBundle]pathForResource:@"student" ofType:@"xml"];
    NSData *data = [[NSData alloc]initWithContentsOfFile:path];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:data error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *students = [rootElement elementsForName:@"student"];
    for (GDataXMLElement *student in students) {
        GDataXMLElement *pidElement = [[student elementsForName:@"pid"] objectAtIndex:0];
        NSString *pid = [pidElement stringValue];
        
        GDataXMLElement *nameElement = [[student elementsForName:@"name"] objectAtIndex:0];
        NSString *name = [nameElement stringValue];
        
        GDataXMLElement *ageElement = [[student elementsForName:@"age"] objectAtIndex:0];
        NSString *age = [ageElement stringValue];
        
        [arr addObject:@{@"pid":pid,@"name":name,@"age":age}];
    }
    
    NSString *lPath = [[NSBundle mainBundle]pathForResource:@"Laytout" ofType:@"xml"];
    NSData *lData = [[NSData alloc]initWithContentsOfFile:lPath];
    GDataXMLDocument *lDoc = [[GDataXMLDocument alloc]initWithData:lData error:nil];
    GDataXMLElement *lRootElement = [lDoc rootElement];
    NSArray *turnArr = [lRootElement elementsForName:@"turntable"];
    
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    textView.text = [NSString stringWithFormat:@"%@",arr];
    [self.view addSubview:textView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
